Repository navigation
Conversation
TopoJson.style_data() wrote each feature's style into the dict given to TopoJson, so a second layer made from the same dict rendered the first layer's style as well. Write the styles into copies of the object path, the geometries and their properties instead, leaving the arcs shared.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TopoJson.style_data()writes each feature's style into the dict that was passed toTopoJson. When two layers are made from the same dict, the second layer is rendered with the first layer's style merged into its own, and a layer without astyle_functionpicks up the styles of the layers before it. The dict the caller passed in also comes back withproperties.styleadded to its geometries.style_data()now writes the styles into copies of the dicts along the object path, of the geometries and of their properties, andself.datapoints at that copy. Styles already present in the input data are kept and merged as before. The arcs and the rest of the topology are shared with the input rather than copied: acopy.deepcopyof the whole topology took the render ofexamples/data/us_counties_20m_topo.jsonfrom about 115 ms to about 380 ms, while with this changestyle_data()on that file (3221 geometries) takes about 1.7 ms instead of 0.8 ms (median of 200 runs).Inputs that already raised on main (an object path that does not exist, a geometry with
"properties": null) still raise, with a different exception type.No linked issue; this was found by reading
TopoJson.style_data().Testing
Python 3.12, numpy 2.5.5, jinja2 3.1.6, branca 0.8.2.
test_topojson_non_collection_geometryandtest_topojson_non_collection_geometry_without_typechecked the style on the dict passed in, which is the behavior this changes, so they now checktopojson.data.test_topojson_style_does_not_change_input_data, which builds two layers from one dict and checks each layer's style and that the dict is unchanged. It fails on main and passes with this change.properties, pre-styled properties, the defaultstyle_function, a single geometry, a nested object path, an empty collection, and aChoroplethwithtopojson=ontests/or_counties_topo.json) gives the same rendered data on main and on this branch.pytest tests --ignore=tests/selenium --ignore=tests/snapshots --ignore=tests/test_repr.py: 426 passed with this change, 425 on main. The same 2 tests fail on both because my environment has no network access and nogeodatasets(test_json_request,test_timedynamic_geo_json).